<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */

if (!defined("Account_lib_include")){
	define("Account_lib_include", 1);
/**
 * 取得查詢帳務區間限制日期
 * @param	strDate 欲查詢起始日期
 * @return	正確傳回 Date
 */
	function getPayupDateOfAccountSearchLimit($strDate, $isSevenDay = false){
		include(__Common_Path."/SysParam.inc.php");
		//print $_KSysParam[AccountMonths].$strDate;
		if($_KSysParam[AccountMonths] >= -1){
			$arrToday = split("-", date("Y-m-d"));
			if($arrToday[2] <= 6 && $_KSysParam[AccountMonths] == 0)$_KSysParam[AccountMonths] = 1;
			if($_KSysParam[AccountMonths] == -1)$_KSysParam[AccountMonths] = 0;
			$intAgentAccountDays = (strlen($_KSysParam[AgentAccountDays]) > 0)?(int)$_KSysParam[AgentAccountDays]:7;
			if($isSevenDay && $arrToday[2] < 29 && $arrToday[2] > 4){
				$strPayupDate = date("Y-m-d", mktime(0, 0, 0, $arrToday[1], $arrToday[2] - $intAgentAccountDays, $arrToday[0]));
			}else{
				$strPayupDate = date("Y-m-d", mktime(0, 0, 0, $arrToday[1] - $_KSysParam[AccountMonths], 1, $arrToday[0]));
			}
			if($strDate < $strPayupDate)$strDate = $strPayupDate;
		}
		return $strDate;
	}

	function isRestrictReport($intLottoID = 1){
		global $_Conn, $$_Conn;
		
		$strSQL = "select * from `bet_BetControl` where `BetKey` in ('OnWagerReult', 'DBNotSync')";
		if(!$RS = PMA_mysql_query($strSQL, $$_Conn))return false;
		//沒任何限制
		if(PMA_mysql_num_rows($RS) == 0)return false;
		//兩種限制都存在
		if(PMA_mysql_num_rows($RS) == 2)return true;
		$Rows = PMA_mysql_fetch_object($RS);
		//結帳中
		if($Rows -> BetKey == "OnWagerReult")return true;
		// 非同步
		$strSQL = "select ID from `bet_Gamble` where LottoID = ".$intLottoID." and isEnd = 0 and GameDate >= CURRENT_DATE()";
		if(!$RS = PMA_mysql_query($strSQL, $$_Conn))return false;
		//沒有彩期
		if(PMA_mysql_num_rows($RS) == 0)return false;
		$Rows = PMA_mysql_fetch_object($RS);
		$intGID = $Rows -> ID;
		//有彩期
		@include(__Common_Path."/todaygame/Gamble".$intLottoID.".inc.php");
		$arrGamble = $_arrGamble[$intGID];
		if(!is_array($arrGamble))return true;	//沒彩期參數資料
		//非同步  有彩期  已結帳
		if($arrGamble["isEnd"] == 1)return true;
		//非同步  有彩期  已過正碼停止下注時間
		if($arrGamble["GameDate"] == date("Y-m-d") && $arrGamble["EndGameTime"] < date("H:i:s"))return true;
		return false;
	}

//-------------------------------------------------------//
//Account_lib End
}
?>